﻿using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;

namespace Devv.Threeter
{
	public partial class StatusControl : UserControl
	{
		#region Properties

		public String ImageLocation
		{
			get
			{
				return imgAvatar.ImageLocation;
			}
			set
			{
				imgAvatar.ImageLocation = value;
			}
		}

		public String Username
		{
			get
			{
				return linkUsername.Text;
			}
			set
			{
				linkUsername.Text = value;
			}
		}

		public new String Text
		{
			get
			{
				return lblMessage.Text;
			}
			set
			{
				lblMessage.Text = value;
			}
		}

		public DateTime Timestamp
		{
			set
			{
				TimeSpan ts = DateTime.Now - value;

				if (ts.Days > 366)
				{
					lblTimestamp.Text = Messages.YearsAgo.Replace("#", Convert.ToInt32(ts.Days / 365).ToString());
				}
				else if (ts.Days > 31)
				{
					lblTimestamp.Text = Messages.MonthsAgo.Replace("#", Convert.ToInt32(ts.Days / 30).ToString());
				}
				else if (ts.Days > 1)
				{
					lblTimestamp.Text = Messages.DaysAgo.Replace("#", ts.Days.ToString());
				}
				else if (ts.Hours > 1)
				{
					lblTimestamp.Text = Messages.HoursAgo.Replace("#", ts.Hours.ToString());
				}
				else if (ts.Minutes > 1)
				{
					lblTimestamp.Text = Messages.MinutesAgo.Replace("#", ts.Minutes.ToString());
				}
				else
				{
					lblTimestamp.Text = Messages.JustPosted;
				}
			}
		}

		#endregion

		#region Main methods

		public StatusControl()
		{
			InitializeComponent();
		}

		private void linkUsername_LinkClicked(Object sender, LinkLabelLinkClickedEventArgs e)
		{
			Process.Start("http://twitter.com/" + ((LinkLabel)sender).Text);
		}

		#endregion

		#region Positioning

		public new void Resize()
		{
			lblTimestamp.Location = new Point(linkUsername.Right + linkUsername.Padding.Right + linkUsername.Margin.Right - 2, lblTimestamp.Top);
		}

		#endregion
	}
}